#include "syscall.h"

/* the datastructures needed*/
int threadID;
/*this is the function used to initialize a particular client with the group count 
information*/
void initProgram()
{
	threadID = GetCurThreadID();
	groupSize = GetInputInt("Users in the group: ", 21);
	if(groupSize <= 0 || groupSize >= MAX_GROUP_SIZE)
	{
		Write("--> Invalid value entered - Setting to default of 4\n",53,1);
		groupSize = 4;
	}
}

void selfRegisteration()
{
	Write("Registering my self on the server\n",35,1);
	SendMessage(0,0,"REG",3);
}

void driver()
{
	/* steps to be followed by the driver */
	/* WAIT FOR ALL THE VISITORS TO LEAVE THE CAR */

}

void networkThread()
{
	threadID = GetCurThreadID();
	while(true)
	{
		ReceiveMessage(threadID, buf, sizeof(buf));
		if(buf[0] == '0')	/* if 0 then it means that the message was meant for registeration*/
		{
			Write("Incorrect message, meant for registeration server\n",50,1);
		}
		else if(buf[0] == '1')	/* if 1 then it means that the sender wants to perform enter CV operation*/
		{
			Write("1\n",1);
		}
		else if(buf[0] == '2')	/* if 2 then it means that sender wants to perform leave CV operation*/
		{
			Write("2\n",1);
		}
		else if(buf[0] == '3')	/*	if 3 then it means that the sender wants to perform wait operation on a particular condition variable*/
		{
			Write("3\n",1);
		}
		else if(buf[0] == '4')	/*	if 4 then it means that the sender wants to perform signal operation on a particular condition variable*/
		{
			Write("4\n",1);
		}
		else if(buf[0] == '5')	/*	if 5 then it means that the sender wants to perform broadcast operation on a particular condition variable*/
		{
			Write("5\n",1);
		}
	}
}


void main()
{
	initProgram();
	selfRegisteration();
}

